home *** CD-ROM | disk | FTP | other *** search
- Path: newshost.cyberramp.net!news
- From: sinan@cyberramp.net (John Noland)
- Newsgroups: comp.lang.c
- Subject: Re: How do I modify a character string that's declared as an array of char?
- Date: 1 Mar 1996 15:42:25 GMT
- Organization: Prose Software
- Distribution: world
- Message-ID: <4h75t1$q7s@newshost.cyberramp.net>
- References: <4gj2nl$840@mirzam.usc.edu> <4gqo63$2pr@newshost.cyberramp.net> <TANMOY.96Feb25203754@qcd.lanl.gov>
- NNTP-Posting-Host: ramp3-28.cyberramp.net
- X-Newsreader: WinVN 0.99.5
-
- In article <TANMOY.96Feb25203754@qcd.lanl.gov>, tanmoy@qcd.lanl.gov says...
- >
- >In article <4gqo63$2pr@newshost.cyberramp.net>
- >sinan@cyberramp.net (John Noland) writes:
- >
- >JN: > char mydata[50];
- >JN: >
- >JN: > strcpy(mydata,"test string");
- >JN: > myfunction(&mydata);
- >JN: ^
- >JN: Dereferencing mydata isn't necessary. mydata is a pointer to the first
- >JN: character of your array, so what you're really doing is passing a pointer
- >JN: to that pointer.
- >
- >Wrong. mydata is an array that usually decays to a pointer to the
- >first character. One place where it does not decay is when it is the
- >operand of &. &mydata is a pointer to the entire array. Read the FAQ
- >for more details.
- >
-
- ANSI treats &mydata as a pointer to the entire array. Some compilers treat
- &mydata as a pointer to the first element. Some compilers disallow &mydata
- constructs altogether. Hence, this is not a portable construct.:-) Use it if
- you like, me, I'll pretend it's not legal. Preferring instead:
-
- char (*p)(50);
-
- p = (char (*)[50]) mydata;
-
-
- Just my opinion. Your code doesn't have to be portable.
-
- -John
-
-